package com.cskaoyan.service.impl;

import com.cskaoyan.bean.bo.GoodsBrandListBo;
import com.cskaoyan.bean.pojo.MarketBrand;
import com.cskaoyan.bean.pojo.MarketBrandExample;
import com.cskaoyan.bean.vo.GoodsBrandListVo;
import com.cskaoyan.mapper.MarketBrandMapper;
import com.cskaoyan.mapper.MarketGoodsMapper;
import com.cskaoyan.service.GoodsBrandService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author :LuoXuXin
 * @version : $version
 * @date :Created in 2022/4/8   20:28
 * @description:
 * @return:
 */
@Service
public class GoodsBrandServiceImpl implements GoodsBrandService {

    @Autowired
    MarketBrandMapper marketBrandMapper;

    @Override
    public GoodsBrandListVo goodsBrandList(GoodsBrandListBo goodsBrandListBo) {
        GoodsBrandListVo goodsBrandListVo = new GoodsBrandListVo();
        //分页
        Integer page = goodsBrandListBo.getPage();
        Integer limit = goodsBrandListBo.getLimit();
        PageHelper.startPage(page,limit);

        //查询所有品牌
        MarketBrandExample marketBrandExample = new MarketBrandExample();
        List<MarketBrand> marketBrands =
                marketBrandMapper.selectByExample(marketBrandExample);
        goodsBrandListVo.setLimit(limit);
        goodsBrandListVo.setPage(page);
        //page工具获得pages  total
        PageInfo<MarketBrand> marketBrandPageInfo = new PageInfo<>(marketBrands);
        goodsBrandListVo.setPages(marketBrandPageInfo.getPages());
        goodsBrandListVo.setTotal(((int) marketBrandPageInfo.getTotal()));
        goodsBrandListVo.setList(marketBrands);
        return goodsBrandListVo;
    }

    @Override
    public MarketBrand goodsBrandDetail(Integer id) {
        MarketBrand marketBrand = marketBrandMapper.selectByPrimaryKey(id);
        return marketBrand;
    }


}
